<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - Apr 13, 2013
 */

    require('top.inc.php');
?>

<?php
if(isset($_SESSION['user']) && $_SESSION['user']['utype'] == 1 || $_SESSION['user']['utype'] == 2 || $_SESSION['user']['utype'] == 3 || $_SESSION['user']['utype'] == 4) {
    $sess_cusID = $_SESSION['user']['cus_id'];
    
    //create new object pass in number of pages and identifier
    $pages = new Paginator(' 50', 'page');
    $total = getCountA('stockout', 'stockout_id', 'cus_id', $sess_cusID, $db);
    $tots = $total[0]['total'];
    $totals = $pages->set_total($tots);
    $limit = $pages->get_limit();
    
    $rows = selectAllWhereWithDateDifference('stockout', $limit, 'cus_id', $sess_cusID, $db);
    
    echo "<h5>Stock Out Report</h5>";
    echo "<table class=\"row-fluid table table-striped table-bordered\">";
            echo "<tr>";
                echo "<th>";
                    echo $stock_out['serialno'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['project_id'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['productid'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['description'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['revisionstate'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['eng_id'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['responsetype'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['requesttime'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['out_docketnumber'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['out_quantity'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['uom'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['requestnumber'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['requestedby'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['siteid'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['boxno'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['warehouseid'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['challannumber'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['receivedtime'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['deliverytime'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['sla'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['receivername'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['cellnumber'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['transportername'];
                echo "</th>";
                echo "<th>";
                    echo $employee['employeename'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['remarks'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['user_id'];
                echo "</th>";
                echo "<th>";
                    echo $stock_out['inserteddate'];
                echo "</th>";
            echo "</tr>";
            
        foreach ($rows as $row) {
            echo "<tr>";
                echo "<td>";
                    echo $row['serialno'];
                echo "</td>";
                echo "<td>";
                    echo getName('projects', 'projectname', 'project_id', $row['project_id'], $db); 
                echo "</td>";
                echo "<td>";
                    echo $row['productid'];
                echo "</td>";
                echo "<td>";
                    echo $row['description'];
                echo "</td>";
                echo "<td>";
                    echo $row['revisionstate'];
                echo "</td>";
                echo "<td>";
                    echo getName('engineerinfo', 'engname', 'eng_id', $row['eng_id'], $db);
                echo "</td>";
                echo "<td>";
                    echo getName('responsetype', 'uniquename', 'responsetype_id', $row['response_type_id'], $db);
                echo "</td>";
                echo "<td>";
                    echo $row['requesttime'];
                echo "</td>";
                echo "<td>";
                    echo $row['out_docketnumber'];
                echo "</td>";
                echo "<td>";
                    echo $row['out_quantity'];
                echo "</td>";
                echo "<td>";
                    echo uomBeauty($row['uom'], $db);
                echo "</td>";
                echo "<td>";
                    echo $row['requestnumber'];
                echo "</td>";
                echo "<td>";
                    echo $row['requestedby'];
                echo "</td>";
                echo "<td>";
                    echo $row['siteid'];
                echo "</td>";
                echo "<td>";
                    echo $row['boxno'];
                echo "</td>";
                echo "<td>";
                   echo getName('warehouses', 'warehousename', 'warehouse_id', $row['warehouseid'], $db); 
                echo "</td>";
                echo "<td>";
                    echo $row['challannumber'];
                echo "</td>";
                echo "<td>";
                    echo $row['receivedtime'];
                echo "</td>";
                echo "<td>";
                    echo $row['deliverytime'];
                echo "</td>";
                echo "<td>";
                    if($row['checkSla'] == 1) {
                        echo "<img src='".CONTENTPATH."/foo-drawer/img/select.png' width='16' />";
                    } else {
                        echo "<img src='".CONTENTPATH."/foo-drawer/img/cross.png' width='16' />";
                    }
                echo "</td>";
                echo "<td>";
                    echo $row['receivername'];
                echo "</td>";
                echo "<td>";
                    echo $row['cellnumber'];
                echo "</td>";
                echo "<td>";
                    echo $row['transportername'];
                echo "</td>";
                echo "<td>";
                    echo getName('employee', 'employeename', 'employee_id', $row['employee_id'], $db); 
                echo "</td>";
                echo "<td>";
                    echo $row['remarks'];
                echo "</td>";
                echo "<td>";
                    echo getName('wms_users', 'username', 'id', $row['userid'], $db);
                echo "</td>";
                echo "<td>";
                    echo $row['inserteddate'];
                echo "</td>";
            echo "</tr>";
        }
    echo "<table>";
    echo $pages->page_links();
} else {
    header("Location: login.php");
}
?>

<?php
    include ('bottom.inc.php');
?>